package com.company.servicename.controller;

import com.company.servicename.config.AuthServiceImpl;
import com.company.servicename.entity.AstUser;
import com.company.servicename.util.ResObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fangsong.zhang
 * @date 2019/9/23 16:45
 * Copyright zfs
 * 类说明: 登录接口
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthServiceImpl authService;

    /**
     * 登录接口
     *
     * @param astUser 用户信息
     * @return token
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResObject login(@RequestBody AstUser astUser) {
        String token = authService.login(astUser);
        if (StringUtils.isEmpty(token)) {
            return ResObject.fail("用户名或密码错误！");
        }
        return ResObject.success(token, false);
    }
}
